const router = require('koa-router')() // koa2路由实现需要依赖koa-router插件

router.prefix('/api/user') // 设置前缀

router.post('/login', function (ctx, next) {
  const { username, password } = ctx.request.body
  ctx.body = 'this is a user response!'
})

router.get('/session-test', function (ctx, next) {
  console.log('cookie',ctx.request.header.cookie);
  if(ctx.session.viewCount == null) {
    ctx.session.viewCount = 0
  }
  ctx.session.viewCount ++
  ctx.body = {
    errno : 0,
    viewCount: ctx.session.viewCount
  }
})

module.exports = router
